<?php 
$attributes = array('class' => 'adminForm ', 'id' => '');
//$hidden = array('url' => $url);
echo form_open(site_url('admin/users'),$attributes);?>
<table class="kunTable">
	<thead>
    	<th width="10"  style="padding:3px 0;text-align:center">{{ helper:lang line="global:identifier" }}</th>
        <!--<th width="10"><input type="checkbox" class="checkAll" /></th>-->
        <!--<th width="120">{{ helper:lang line="users:username" }}</th> -->
        <th width="120">{{ helper:lang line="users:display_name" }}</th>  
		<th width="70">{{ helper:lang line="users:salary2" }} <a data-toggle = "tooltip" 
			data-original-title="{{helper:lang line='global:save'}}" 
			data-url="emp_profile/update_salary2"
			class="btn-save tooltips save-salary2">
			
			{{theme:image file ='_icon/icon-32-save.png' }}
		</a></th>		
		<th width="70">{{ helper:lang line="users:salary" }} <a data-toggle = "tooltip" 
			data-original-title="{{helper:lang line='global:save'}}" 
			data-url="emp_profile/update_salary"
			class="btn-save tooltips save-salary">
			{{theme:image file ='_icon/icon-32-save.png' }}
		</a></th>
		
		<!--<th width="60">{{ helper:lang line="users:factor" }} <a data-toggle = "tooltip" 
			data-original-title="{{helper:lang line='global:save'}}" 
			class="tooltips save-factor" style="height:32px;display:inline-block;width:32px;overflow:hidden;">
			
			{{theme:image file ='_icon/icon-32-save.png' }}
		</a></th>-->
		<th width="70">{{ helper:lang line="users:s1" }} <a data-toggle = "tooltip" 
			data-original-title="{{helper:lang line='global:save'}}" 
			data-url="emp_profile/update_s1"
			class="btn-save tooltips save-s1">
			
			{{theme:image file ='_icon/icon-32-save.png' }}
		</a></th>
		<th width="70">{{ helper:lang line="users:s2" }} <a data-toggle = "tooltip" 
			data-original-title="{{helper:lang line='global:save'}}" 
			data-url="emp_profile/update_s2"
			class="btn-save tooltips save-s2">
			
			{{theme:image file ='_icon/icon-32-save.png' }}
		</a></th>   		
		<th width="70">{{ helper:lang line="global:action" }}</th>
    </thead>
    <tbody>
    	{{model}}
        <tr>
           	<td>
               	{{ helper:count identifier }}
               </td>
               <!--<td><input type="checkbox" class="checkGroup" value="{{id}}" /></td>-->
               <!--<td>{{username}}</td>-->
               <td class="upc">{{display_name}}</td>
			   <td>
				<input type="hidden" value="{{id}}" class="user-id" />
				<input type="text" value="{{helper:number value = salary2}}" data-show="save-salary2" uid="{{id}}" class="txt-profile large" />
				</td>
			   <td>
				<input type="hidden" value="{{id}}" class="user-id" />
				<input type="text" value="{{helper:number value = salary}}" data-show="save-salary" uid="{{id}}" class="txt-profile large" />
				</td>
				
				<!--<td>
				<input type="hidden" value="{{id}}" class="user-id" />
				<input type="text" value="{{factor}}" uid="{{id}}" class="txt-profile" />
				</td>-->
				<td>
				<input type="hidden" value="{{id}}" class="user-id" />
				<input type="text" value="{{helper:number value = s1}}" data-show="save-s1" uid="{{id}}" class="txt-profile large" />
				</td>
				<td>
				<input type="hidden" value="{{id}}" class="user-id" />
				<input type="text" value="{{helper:number value = s2}}" data-show="save-s2" uid="{{id}}" class="txt-profile large" />
				</td>
			<td>
			{{button:href: class="edit" title={helper:lang line="global:edit"} data-toggle="tooltip" 
                		href={url:site uri="admin/users/edit/{{id}}"} }}
            {{button:href: class="del" title={ helper:lang line="global:delete"} data-toggle="tooltip" 
                		href={url:site uri="admin/users/delete/{{id}}"} }}
			{{button:href: class="status" title={ helper:lang line="users:off:{{s_up}}"} data-toggle="tooltip"
                		href={url:site uri="admin/users/active/{{id}}/{{s_up}}"} }}
			{{button:href: class="status_hd" title={ helper:lang line="users:hd:{{s_hd}}"} data-toggle="tooltip"
                		href={url:site uri="admin/users/status/{{id}}/{{s_hd}}"} }}
			</td>
        </tr>
		{{/model}}
    </tbody>
</table>
<button value="enable" data-ajax = "<?php echo base_url('admin/users/active_select')?>"></button>
<?php echo form_close();?>

<script type="text/javascript">
$today = '{{today}}';
$('a.status').click(function(){
	$mess = confirm($(this).text() +' ?');//prompt
	$s = parseInt('{{s_up}}');
	if($mess){
		if($s == 2)//nghi viec
		{
			var date = prompt("Ngày nghỉ việc (ngày - tháng - năm)");
			if (date != null){
				$url = $(this).attr('href')+"/"+date;
				//alert($url);
				location.href = $(this).attr('href')+"/"+date;
				return false;
			}
			
		}
		return true;
	}
	return false;
});
//ky hop dong
$('a.status_hd').click(function(){
	$mess = confirm($(this).text() +' ?');//prompt
	$s = parseInt('{{s_hd}}');

	if($mess){
		if($s == 1)//hoi ky hd ko
		{
			var date = prompt("Ngày ký hợp đồng (ngày - tháng - năm)",$today);
			
			if (date != null){
				$url = $(this).attr('href')+"/"+date;
				//alert($url);
				location.href = $(this).attr('href')+"/"+date;
				return false;
			}
			
		}
		return true;
	}
	return false;
});

kunkun.tooltips.call();
kunkun.checkAll.call();
$update_suss = "{{helper:lang line = 'global:update_success'}}";
$('.actionBtn li.enable a').click(function(){
	
});

$('input.txt-profile').bind('keypress',function(){
	$uid = $(this).attr('uid');
	$data_show = $(this).attr('data-show');
	
	$('.btn-save').removeClass('d-block');
	$('.'+$data_show).addClass('d-block');
	
	$(this).attr('name','data['+$uid+']');
	
});


$('.btn-save').click(function(){
	$url = $(this).attr('data-url');
	$salary = $('.adminForm ').serialize();
	$.ajax({
		url:'{{url:site uri="'+$url+'"}}',
		data:$salary,
		type:'post',
		success:function(){
			up_success();
		}
	});
});

function up_success(){
	alert($update_suss);
	location.reload();
}

/*
37 - left
38 - up
39 - right
40 - down*/
$('input.txt-profile').keydown(function(e){
	var eq = 0;
	$data = $(this).attr('data-show');
	$list = $('input[data-show="'+$data+'"]');
	
	for($i = 0; $i< $list.length; $i++){
		if($list.eq($i).is($(this)))
			eq = $i;
	}
	if (e.keyCode == 38)  // up
      $list.eq(eq-1).focus(); 
    if (e.keyCode == 40) { //down
      $list.eq(eq+1).focus();
	  if((eq + 1) == $list.length){
		$list.eq(0).focus();
		$('html').scrollTop(0);
	  }
    }
});
</script>